Skip to content

发送数据 - TcpClientSend

函数简介

发送数据(异步操作)。

接口名称

TcpClientSend

DLL调用

c
int32_t TcpClientSend(int64_t instance, int64_t client_handle, int64_t data, int32_t data_len);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
client_handle长整数型客户端句柄
data长整数型数据指针
data_len整数型数据长度

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long client = ola.TcpClientCreate(nullptr, 0, 0);
ola.TcpClientConnect(client, "127.0.0.1", 9000);
// 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long client = ola.TcpClientCreate(nullptr, 0, 0);
ola.TcpClientConnect(client, "127.0.0.1", 9000);
// 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
client = ola.TcpClientCreate(nullptr, 0, 0)
ola.TcpClientConnect(client, "127.0.0.1", 9000)
# 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long client = ola.TcpClientCreate(nullptr, 0, 0);
ola.TcpClientConnect(client, "127.0.0.1", 9000);
// 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen);
cpp
var ola = com("OlaPlug.OlaSoft")
var client = ola.TcpClientCreate(nullptr, 0, 0)
ola.TcpClientConnect(client, "127.0.0.1", 9000);
// 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen);
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
client = ola.TcpClientCreate(nullptr, 0, 0)
ola.TcpClientConnect(client, "127.0.0.1", 9000);
' 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen);
text
.局部变量 ola, OLAPlug
ola.创建 ()
client = ola.TcpClientCreate(nullptr, 0, 0)
ola.TcpClientConnect(client, "127.0.0.1", 9000)
' 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var client = ola.TcpClientCreate(nullptr, 0, 0);
ola.TcpClientConnect(client, "127.0.0.1", 9000);
// 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 client = ola.TcpClientCreate(nullptr, 0, 0)
ola.TcpClientConnect(client, "127.0.0.1", 9000);
// 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen);
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long client = ola.TcpClientCreate(nullptr, 0, 0);
ola.TcpClientConnect(client, "127.0.0.1", 9000);
// 发送 UTF-8 文本需自行准备 buffer 指针
ola.TcpClientSend(client, (long)dataPtr, dataLen);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long client = TcpClientCreate(instance, nullptr, 0, 0);
TcpClientConnect(instance, client, "127.0.0.1", 9000);
TcpClientSend(instance, client, (long)dataPtr, dataLen);
csharp
long instance = CreateCOLAPlugInterFace();
long client = TcpClientCreate(instance, nullptr, 0, 0);
TcpClientConnect(instance, client, "127.0.0.1", 9000);
TcpClientSend(instance, client, (long)dataPtr, dataLen);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
client = TcpClientCreate(instance, nullptr, 0, 0)
TcpClientConnect(instance, client, "127.0.0.1", 9000)
TcpClientSend(instance, client, (long)dataPtr, dataLen)

返回值

整数型,1 成功(加入发送队列),0 失败。

注意事项

  • 这是异步操作,数据会被加入发送队列
  • 发送完成后会触发回调(event_type=4)
  • 如果启用了分包协议,会自动添加4字节长度前缀
  • 如果未连接,发送会失败
  • 数据会被复制,调用后可以立即释放原始数据